package com.hudson.core.concurrent.threadpool;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class HudsonThreadFactory implements ThreadFactory {
    private final String namePrefix;
    private final AtomicInteger threadIndex = new AtomicInteger(1);

    public HudsonThreadFactory(String namePrefix) {
        this.namePrefix = namePrefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r, namePrefix + "-" + threadIndex.getAndIncrement());
        // 可选：设置线程属性，如是否为守护线程
        // t.setDaemon(true);
        return t;
    }
}
